@isTest
private class UpsertExWarehouseRESTTest {
    static testMethod void testMethod1() {
        TestUtils.createUsers();
        User appMan = [SELECT Id,Name FROM User WHERE Name='用户1' LIMIT 1];
		
		//创建客户
		Account acc1 = TestUtils.createAccount();
		acc1.Name = '四川省sc迈克实业有限公司';
		acc1.AccountNumber = 'AN.0001';
		insert acc1;
		Account acc2 = TestUtils.createAccount();
		acc2.Name = '成都市sc第一人民医院';
		acc2.AccountNumber = 'AN.0002';
		insert acc2;
        
        ProductStructure__c ps = new ProductStructure__c();
        ps.Classify3__c = '试剂';
        insert ps;
        //创建产品
		Product__c pro1 = TestUtils.createProduct();
		pro1.Name = '尿有形成份检测稀释液UPS-1';
		pro1.NCCode__c = 'P-0001';
        pro1.ProductStructure__c = ps.Id;
		insert pro1;
		Product__c pro2 = TestUtils.createProduct();
		pro2.Name = '尿有形成份检测稀释液UPS-2';
		pro2.NCCode__c = 'P-0002';
        pro2.ProductStructure__c = ps.Id;
		insert pro2;
		//创建联系人
        Contact con = TestUtils.createContact();
        con.MobilePhone = '13588885555';
        con.Post__c = '科长/主任';

		//创建合同
        Contract__c ctr = TestUtils.createContract();
        ctr.Account__r = acc1;
        ctr.ContractNo__c = '123456';
        ctr.Corpcode__c = 'MKSY';
        insert ctr;
		//创建订单
        Order__c ord = TestUtils.createOrder();
        ord.Account__c = acc1.Id;
        ord.Contact__c = con.Id;
        ord.Contract__c = ctr.Id;
        ord.Name = 'OP.2017010001';
        ord.NCsale_hid__c = '1';
        insert ord;
        //创建订单明细 
        Order_Product__c op1 = new Order_Product__c();
        op1.NCsalecode__c = 'OP.2017010001';
        op1.Order__c = ord.Id;
        op1.Original_Price__c = 21;
        op1.Quote_Price__c = 25;
        op1.Product__c = pro1.Id;
        op1.NCsale_bid__c = '1';
        insert op1;
        Order_Product__c op2 = new Order_Product__c();
        op2.NCsalecode__c = 'OP.2017010001';
        op2.Order__c = ord.Id;
        op2.Original_Price__c = 43;
        op2.Quote_Price__c = 56;
        op2.Product__c = pro2.Id;
        op2.NCsale_bid__c = '2';
        insert op2;
        //创建出库单
        ExWarehouse__c eh = new ExWarehouse__c();
        eh.Name = 'OH-2017010001';//出库单号
        eh.cgeneralhid__c = '1242';//出库单主表ID
        eh.ckname__c = '试剂仓';//仓库
    	eh.dbilldate__c = Date.valueOf('2017-01-01');//出库日期
    	eh.currtypename__c = 'RMB';//币种
    	eh.corpcode__c = 'CP-001';//公司编码
        eh.corpname__c = '四川省迈克实业有限公司';//公司名称
        eh.custcode__c = 'AN.0001';//客户编码
        eh.custname__c = '四川省迈克实业有限公司';//客户名称
        eh.Account__c = acc1.Id;
        insert eh;
        ExWarehouse_Detail__c ewt = new ExWarehouse_Detail__c();
        ewt.Name = '2342';
        ewt.ExWarehouse__c = eh.Id;
        ewt.outcode__c = 'OH-2017010001';//出库单号
    	ewt.salecode__c = 'OP.2017010001';//销售订单号
    	ewt.sale_hid__c = '1';//销售订单主表ID
        ewt.sale_bid__c = '2';//销售订单从表ID
    	ewt.invcode__c = 'P-0001';//存货编码
    	ewt.invname__c = '尿有形成份检测稀释液UPS-1';//存货名称
    	ewt.invdm__c = '655455';//存货代码
        ewt.Product__c = pro1.Id;//产品
    	ewt.vbatchcode__c = '1';//批次号
        ewt.nshouldoutnum__c = 300;//应发数量
        ewt.nnum__c = 200;//实发数量
        ewt.dproducedate__c = Date.valueOf('2016-02-22');//生产日期
        ewt.dvalidate__c = Date.valueOf('2018-05-29');//失效日期
        insert ewt;

		Test.startTest();
		//测试
		List<UpsertExWarehouseREST.ExWarehouseRestArgs> args = new List<UpsertExWarehouseREST.ExWarehouseRestArgs>();
		UpsertExWarehouseREST.upsertExWarehouse(args);

		UpsertExWarehouseREST.ExWarehouseRestArgs arg1 = new UpsertExWarehouseREST.ExWarehouseRestArgs();
		arg1.dbillcode = 'OH-2017010001';//出库单号
        arg1.ckname = '试剂仓';//仓库
    	arg1.dbilldate = '2017-01-01';//出库日期
    	arg1.currtypename = 'RMB';//币种
    	arg1.corpcode = 'CP-001';//公司编码
        arg1.corpname = '四川省迈克实业有限公司';//公司名称
        arg1.custcode = 'AN.0001';//客户编码
        arg1.custname = '四川省迈克实业有限公司';//客户名称
    	//从表数据
        arg1.salecode = 'OP.2017010001';//销售订单号
        arg1.sale_hid = '1';//销售订单主表ID
        arg1.sale_bid = '2';//销售订单从表ID
        arg1.invcode = 'P-0001';//存货编码
        arg1.invname = '尿有形成份检测稀释液UPS-1';//存货名称
        arg1.invdm = '655455';//存货代码
        arg1.vbatchcode = '1';//批次号
        arg1.nshouldoutnum = '300';//应发数量
        arg1.nnum = '300';//实发数量
        arg1.dproducedate = '2016-01-01';//生产日期
        arg1.dvalidate = '2018-01-01';//失效日期
		arg1.ts = '2017-01-01 15:00:00';
        arg1.cgeneralhid = '1242';
        
        arg1.rowno = '11';//行号
        arg1.memo = 'ces';//终端客户
        arg1.sa03 = 'ces';
        arg1.kpfs = 'ces';
        arg1.sflx = 'ces';
        arg1.bodyname = 'ces';
        arg1.ck = 'ces';
        arg1.cbiztype = 'ces';
        arg1.ywyname = 'ces';
        arg1.deptname = 'ces';
        arg1.xsqy = 'ces';
        arg1.ntaxrate = 'ces';
        arg1.iszx = 'ces';
        arg1.isfq = 'ces';
        arg1.so01 = 'ces';
        arg1.mk01 = 'ces';
        arg1.mk2 = 'ces';
        arg1.noriginalcursummny = 'ces';
        arg1.invtype = 'ces';
        arg1.invspec = 'ces';
        arg1.jldw = 'ces';
        arg1.nquotemny = 'ces';
        arg1.vreceiveaddress = 'ces';
        arg1.addrname = 'ces';
        arg1.addrphone = 'ces';
        arg1.dbizdate = 'ces';
        arg1.vbodynote = 'ces';
        arg1.csourcetype = 'ces';
        arg1.cfirsttype = 'ces';
        arg1.invpinpai = 'ces';
        arg1.cinvbasid = 'P-0002';
        arg1.def8 = 'ces';
        arg1.invshortname = 'ces';
        arg1.dr = 'ces';
        arg1.vstorecondition = 'ces';
        arg1.vdotechnics = 'ces';
        arg1.vapprovalnum = 'ces';
		args.add(arg1);
		
		UpsertExWarehouseREST.ExWarehouseRestArgs arg2 = new UpsertExWarehouseREST.ExWarehouseRestArgs();
		arg2.dbillcode = 'OH-2017010001';//出库单号
        arg2.ckname = '试剂仓';//仓库
    	arg2.dbilldate = '2017-01-01';//出库日期
    	arg2.currtypename = 'RMB';//币种
    	arg2.corpcode = 'CP-001';//公司编码
        arg2.corpname = '四川省迈克实业有限公司';//公司名称
        arg2.custcode = 'AN.0001';//客户编码
        arg2.custname = '四川省迈克实业有限公司';//客户名称
    	//从表数据
        arg2.salecode = 'OP.2017010001';//销售订单号
        arg2.sale_hid = '1';//销售订单主表ID
        arg2.sale_bid = '3';//销售订单从表ID
        arg2.invcode = 'P-0002';//存货编码
        arg2.invname = '尿有形成份检测稀释液UPS-2';//存货名称
        arg2.invdm = '655451';//存货代码
        arg2.vbatchcode = '1';//批次号
        arg2.nshouldoutnum = '700';//应发数量
        arg2.nnum = '300';//实发数量
        arg2.dproducedate = '2016-04-01';//生产日期
        arg2.dvalidate = '2018-03-31';//失效日期
		arg2.ts = '2017-01-01 15:55:23';
		args.add(arg2);
		
		UpsertExWarehouseREST.upsertExWarehouse(args);
		
		UpsertExWarehouseREST.ExWarehouseRestArgs arg3 = new UpsertExWarehouseREST.ExWarehouseRestArgs();
		arg3.dbillcode = 'OH-2017010002';//出库单号
        arg3.ckname = '试剂仓';//仓库
    	arg3.dbilldate = '2017-01-01';//出库日期
    	arg3.currtypename = 'RMB';//币种
    	arg3.corpcode = 'CP-001';//公司编码
        arg3.corpname = '四川省迈克实业有限公司';//公司名称
        arg3.custcode = 'AN.0002';//客户编码
        arg3.custname = '成都市第一人民医院';//客户名称
    	//从表数据
        arg3.salecode = 'OP.2017010001';//销售订单号
        arg3.sale_hid = '2';//销售订单主表ID
        arg3.sale_bid = '5';//销售订单从表ID
        arg3.invcode = 'P-00013';//存货编码
        arg3.invname = '尿有形成份检测稀释液UPS-1';//存货名称
        arg3.invdm = '623451';//存货代码
        arg3.vbatchcode = '2';//批次号
        arg3.nshouldoutnum = '500';//应发数量
        arg3.nnum = '500';//实发数量
        arg3.dproducedate = '2016-04-01';//生产日期
        arg3.dvalidate = '2018-03-31';//失效日期
		arg3.ts = '2017-01-01 17:55:24';
		args.add(arg3);

		UpsertExWarehouseREST.ExWarehouseRestArgs arg4 = new UpsertExWarehouseREST.ExWarehouseRestArgs();
		arg4.dbillcode = 'OH-2017010003';//出库单号
        arg4.ckname = '试剂仓';//仓库
    	arg4.dbilldate = '2017-01-01';//出库日期
    	arg4.currtypename = 'RMB';//币种
    	arg4.corpcode = 'CP-001';//公司编码
        arg4.corpname = '四川省迈克实业有限公司';//公司名称
        arg4.custcode = 'AN.0002';//客户编码
        arg4.custname = '成都市第一人民医院';//客户名称
    	//从表数据
        arg4.salecode = 'OP.2017010001';//销售订单号
        arg4.sale_hid = '3';//销售订单主表ID
        arg4.sale_bid = '8';//销售订单从表ID
        arg4.invcode = 'P-0001';//存货编码
        arg4.invname = '尿有形成份检测稀释液UPS-1';//存货名称
        arg4.invdm = '434544';//存货代码
        arg4.vbatchcode = '1';//批次号
        arg4.nshouldoutnum = '800';//应发数量
        arg4.nnum = '200';//实发数量
        arg4.dproducedate = 'sdsds';//生产日期
        arg4.dvalidate = '2sdfsd';//失效日期
		arg4.ts = '2017-01-01 18:35:55';
		args.add(arg4);
		
		UpsertExWarehouseREST.upsertExWarehouse(args);

		UpsertExWarehouseREST.ExWarehouseRestArgs arg5 = new UpsertExWarehouseREST.ExWarehouseRestArgs();
		arg5.dbillcode = 'OH-2017010002.OH-2017010002.OH-2017010002.OH-2017010002.OH-2017010002.OH-2017010002.OH-2017010002.OH-2017010002.OH-2017010002.OH-2017010002.OH-2017010002.OH-2017010002.OH-2017010002';//出库单号
        arg5.ckname = '试剂仓';//仓库
    	arg5.dbilldate = 'sdfsdf';//出库日期
    	arg5.currtypename = 'RMB';//币种
    	arg5.corpcode = 'CP-001';//公司编码
        arg5.corpname = '四川省迈克实业有限公司';//公司名称
        arg5.custcode = 'AN.0002';//客户编码
        arg5.custname = '成都市第一人民医院';//客户名称
    	//从表数据
        arg5.salecode = 'OP.2017010001';//销售订单号
        arg5.sale_hid = '8';//销售订单主表ID
        arg5.sale_bid = '9';//销售订单从表ID
        arg5.invcode = 'P-0001';//存货编码
        arg5.invname = '尿有形成份检测稀释液UPS-1';//存货名称
        arg5.invdm = '434544';//存货代码
        arg5.vbatchcode = '1';//批次号
        arg5.nshouldoutnum = 'dsd';//应发数量
        arg5.nnum = 'dsds';//实发数量
        arg5.dproducedate = 'sdsds';//生产日期
        arg5.dvalidate = '2sdfsd';//失效日期
		arg5.ts = '2017-01-01 18:35:55';
        args.add(arg5);

        UpsertExWarehouseREST.upsertExWarehouse(args);

		Test.stopTest();
    }
}